package cn.ranko.site.service;

import cn.ranko.bean.easyui.DataGridParam;
import cn.ranko.site.mapper.SysRolesMapper;
import cn.ranko.site.model.SysRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ZJ08 on 2016/8/5.
 */
@Service
public class SysRolesService {

    @Autowired
    SysRolesMapper sysRolesMapper;

    /**
     * 获取所有的角色数据，有效角色
     *
     * @return
     */
    public List<SysRoles> getRows() {
        return sysRolesMapper.getRows();
    }

    /**
     * 根据主键获取角色信息
     *
     * @param id
     * @return
     */
    public SysRoles getById(Long id) {
        return sysRolesMapper.selectByPrimaryKey(id);
    }

    public void saveRoles(SysRoles roles) {
        if(roles.getId() == 0){
            //新增
            sysRolesMapper.insertSelective(roles);
        }else{
            sysRolesMapper.updateByPrimaryKeySelective(roles);
        }
    }

    /**
     * 根据主键删除操作，设置available为0
     * @param id
     */
    public void deleteByIds(Long id) {
        SysRoles roles = new SysRoles();
        roles.setId(id);
        roles.setAvailable(false);
        sysRolesMapper.updateByPrimaryKeySelective(roles);
    }
}
